home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power Programmierung
/
Power-Programmierung (Tewi)(1994).iso
/
magazine
/
drdobbs
/
1988
/
03
/
porter
/
porter.ls2
< prev
Wrap
Text File
|
1979-12-31
|
3KB
|
108 lines
Program hugemats;
{ Demo program to add two huge matrices > 64K, giving a third }
Const maxRows = 250;
maxCols = 300;
Type dataObj = word;
colPtr = ^colArray;
colArray = array [1..maxCols] of dataObj;
colNode = record
col : colPtr;
End;
rowPtr = ^rowArray;
rowArray = array [1..maxRows] of colNode;
Var A, B, C : rowPtr;
x, y : word;
error : Boolean;
{ ------------------------------------------------------------- }
Procedure create (var D : rowPtr;
var error : Boolean);
{ Create huge array 'D' and pass back pointer to it }
Var row : word;
Begin
Error := false;
If maxAvail > sizeof (rowArray) then { if space available }
GetMem (D, sizeof (rowArray)) { allocate row array }
Else begin
D := nil;
Error := true;
End;
If D <> nil then
For row := 1 to maxRows do begin { allocate all rows }
If not error then
If maxAvail > sizeof (colArray) then { if space }
GetMem (D^ [row].col, sizeof (colArray)) { alloc row }
Else
Error := true;
End;
End;
{ --------------------------- }
Procedure acquire (var D : rowPtr;
var error : Boolean);
{ Load data into array 'D' after creating it }
Var row, c : word;
Begin
Create (D, error);
If not error then
For row := 1 to maxRows do
For c := 1 to maxCols do
D^ [row].col^ [c] := (row * 10) + c; { modify to suit }
End;
{ --------------------------- }
Begin { main program }
Writeln ('Size of each array is ',
sizeof (rowArray) + (sizeof (colArray) * maxRows),
' bytes');
Writeln ('Initial heap space = ', memAvail);
Writeln ('Setting up array A');
Acquire (A, error);
If not error then begin
Writeln ('Remaining heap space = ', memAvail : 6);
Writeln ('Setting up array B');
Acquire (B, error);
End;
If not error then begin
Writeln ('Remaining heap space = ', memAvail : 6);
Writeln ('Creating target array C');
Create (C, error);
End;
If not error then
Begin
Writeln ('Remaining heap space = ', memAvail : 6);
Writeln ('Adding arrays');
For y := 1 to maxRows do
For x := 1 to maxCols do
C^[y].col^[x] := A^[y].col^[x] + B^[y].col^[x];
Writeln;
Writeln ('Proof:');
Write ('A [1, 1] + B [1, 1] = C [1, 1] = ');
Writeln (A^[1].col^[1] : 5, ' + ', B^[1].col^[1] : 5, ' = ',
C^[1].col^[1] : 5);
x := maxCols;
y := maxRows;
Write ('A [m, n] + B [m, n] = C [m, n] = ');
Writeln (A^[y].col^[x] : 5, ' + ', B^[y].col^[x] : 5, ' = ',
C^[y].col^[x] : 5);
End
Else
Begin
Writeln ('Out of memory: program ended');
Write (#7); { beep }
End;
End.